package com.eml.service.dao.impl;

import com.eml.service.dao.MerchantDao;
import com.eml.service.entity.Merchant;
import com.eml.service.util.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class MerchantDaoImpl implements MerchantDao {
    @Override
    public Merchant merchantsRegister(Merchant merchant) throws Exception {
            Connection connection = JDBCUtils.getConnection ();
            String sql = "insert into merchant (merchant_accontname,merchant_password,merchant_phone,merchant_name) values (?,?,?,?)";
            PreparedStatement psmt = connection.prepareStatement (sql);
            psmt.setString (1, merchant.getMerchant_accontname ());
            psmt.setString (2, merchant.getMerchant_password ());
            psmt.setString (3, merchant.getMerchant_phone ());
            psmt.setString (4, merchant.getMerchant_name ());
            psmt.executeUpdate ();
            JDBCUtils.close (connection, psmt);
        return null;
    }

    @Override
    public Merchant selectByMerchantname(String merchantname) throws Exception {
        Connection connection = JDBCUtils.getConnection ();
        String sql =
 "select merchant_id,merchant_accontname,merchant_password,merchant_phone,merchant_name from merchant where merchant_accontname = ?";
        PreparedStatement psmt = connection.prepareStatement (sql);
        psmt.setString (1, merchantname);
        ResultSet rs = psmt.executeQuery ();
        if (rs.next ()){
            int id = rs.getInt ("merchant_id");
            String acountname = rs.getString ("merchant_accontname");
            String password = rs.getString ("merchant_password");
            String phone = rs.getString ("merchant_phone");
            String name = rs.getString ("merchant_name");
            JDBCUtils.close (connection,psmt,rs);
            return new Merchant (id,acountname,password,phone,name);
        }
        JDBCUtils.close (connection,psmt,rs);
        return null;
    }

    @Override
    public void updateMerchantsBasicInformation() throws Exception {

    }

    @Override
    public void updateMerchantsPassword() throws Exception {

    }

    @Override
    public void selectMerchantInfo() throws Exception {

    }

    @Override
    public void initiateTakeOrdersRequest() throws Exception {

    }

    @Override
    public void writeTakeOrdersInfo() throws Exception {

    }

    @Override
    public void commitTakeOrdersRequest() throws Exception {

    }

    @Override
    public void receivedOrder() throws Exception {

    }

    @Override
    public void checkOrderBasicInfo() throws Exception {

    }

    @Override
    public void prepareProducts() throws Exception {

    }

    @Override
    public void sendDeliveryRequest() throws Exception {

    }

    @Override
    public void commitDeliveryRequest() throws Exception {

    }

}



